#include <string>
#include <gl/glew.h>
#include <gl/glut.h>
#include <cg/cgGL.h>
#include "TextureFormats.h"



class Kernel {
public:
	Kernel(unsigned width, unsigned height, TexParam &param, const char *shaderFile);
	~Kernel();
	void calc(float *bodies, float *accels, float eps);
private:
	void initCG(const char *shaderFile);
	void initData();
	void createTexture(GLuint texID);
	void sendToTexture(GLuint texID, float *data);
	void getFromTexture(GLuint texID, float *data);
	void swap();
	std::string loadShader(const char *shaderFile);

	unsigned width, height;
	TexParam param;
	CGcontext context;
	CGprofile profile;
	CGprogram program;
	CGparameter accelsParam, bodiesParam, sizeParam, epsParam;
	GLuint bodiesTexID, accelsTexID[2];
	int attachIndex[2];
	static const GLenum attach[];
	int readIndex, writeIndex;
};
